package com.manor.main.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.manor.main.R;
import com.manor.main.bean.SdListBean;
import com.manor.main.custom.marqueeview.Utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class SdListAdapter extends BaseQuickAdapter<SdListBean.RecordsBean, BaseViewHolder> {
    String type = "0";

    public SdListAdapter(int layoutResId, @Nullable List<SdListBean.RecordsBean> data, String type) {
        super(layoutResId, data);
        this.type = type;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, SdListBean.RecordsBean item) {
//        switch (item.getType()){
//            case 1:
//                helper.setText(R.id.tv_name, "充值");
//                break;
//            case 2:
//                helper.setText(R.id.tv_name, "购买贵族");
//                break;
//            case 3:
//                helper.setText(R.id.tv_name, "购买道具");
//                break;
//            case 4:
//                helper.setText(R.id.tv_name, "购买矿石");
//                break;
//            case 5:
//                helper.setText(R.id.tv_name, "购买礼品");
//                break;
//            case 6:
//                helper.setText(R.id.tv_name, "认证");
//                break;
//        }
        helper.setText(R.id.tv_name, item.getType());
       TextView tv_context=  helper.getView(R.id.tv_context);
        tv_context.setVisibility(View.GONE);
        //1收入 2支出
            helper.setText(R.id.tv_money,item.getTransType()==2 ? "-" + item.getSdCoupons().toString()+"嗨券" : "+" + item.getSdCoupons().toString()+"嗨券");
        helper.setText(R.id.tv_time, item.getCreateTime());

        ImageView im_type = helper.getView(R.id.im_type);
        ViewGroup.LayoutParams lp;
        lp=im_type.getLayoutParams();
        im_type.setImageResource(R.mipmap.pic_sdj);
        lp.width= Utils.sp2px(getContext(), 16);
        lp.height=Utils.sp2px(getContext(), 16);
        im_type.setLayoutParams(lp);
    }

    public String dateToStamp(String s) throws ParseException {
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //如果它本来就是long类型的,则不用写这一步
        long lt = new Long(s);
        Date date = new Date(lt*1000);
        res = simpleDateFormat.format(date);
        return res;

    }

}